package year2022.month123;

public class ThreadTest {

    public static void main(String[] args) {
        Person person = new Person();

        for (int i=0; i<10; i++){
            Thread t = new Thread(new MyThread(person, i));
            t.start();
        }
    }

}

class MyThread implements Runnable{

    private Person person;

    public MyThread(Person person, int age){
        this.person = person;
        this.person.setName("Test"+age);
        this.person.setAge(age);
    }

    @Override
    public void run() {
        System.out.println(person.getName() + "\t" + person.getAge());
    }
}

class Person{
    private volatile String name;
    private volatile Integer age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
